home *** CD-ROM | disk | FTP | other *** search
/ Disc to the Future 2 / Disc to the Future Part II Programmer's Reference (Wayzata Technology)(6013)(1992).bin / MAC / THINKC / 5 / MACVOGL- / EXAMPLES / LCUBE.C < prev    next >
C/C++ Source or Header  |  1992-07-19  |  3KB  |  182 lines

  1.  
  2. #include <stdio.h>
  3.  
  4. #ifdef SGI
  5. #include "gl.h"
  6. #include "device.h"
  7. #else
  8. #include "vogl.h"
  9. #include "vodevice.h"
  10. #endif
  11.  
  12. #define    CUBE_SIZE    200.0
  13. #define    TRANS        25.0
  14. #define    SCAL        0.1
  15.  
  16. main()
  17. {
  18.         char    *p;
  19.     float    tdir = TRANS;
  20.     float    scal = 1.0 + SCAL;
  21.     int    but, nplanes;
  22.     int    x, y, i, n;
  23.     short    val;
  24.  
  25.     prefsize(500L, 500L);
  26.  
  27.     winopen("lcube");
  28.  
  29.     unqdevice(INPUTCHANGE);
  30.     qdevice(SKEY);
  31.     qdevice(XKEY);
  32.     qdevice(YKEY);
  33.     qdevice(ZKEY);
  34.     qdevice(EQUALKEY);
  35.     qdevice(MINUSKEY);
  36.     qdevice(ESCKEY);
  37.     qdevice(QKEY);
  38.     
  39.  
  40.     window(-800.0, 800.0, -800.0, 800.0, -800.0, 800.0);
  41.     lookat(0.0, 0.0, 1500.0, 0.0, 0.0, 0.0, 0);
  42.  
  43.     if ((nplanes = getplanes()) == 1)
  44.         makecubes(0);
  45.  
  46.     makecubes(1);
  47.  
  48.     backface(1);
  49.         
  50.     doublebuffer(1);
  51.     gconfig();
  52.  
  53.     /*
  54.      * Doublebuffer does a backbuffer(TRUE)....
  55.      */
  56.  
  57.     while(1) {
  58.         x = 500 - (int)getvaluator(MOUSEX);
  59.         y = 500 - (int)getvaluator(MOUSEY);
  60.         x *= 3;
  61.         y *= 3;
  62.         pushmatrix();
  63.             rotate(x, 'y');
  64.             rotate(y, 'x');
  65.             color(BLACK);
  66.             clear();
  67.             callobj((Object)3);
  68.             if (nplanes == 1)
  69.                 callobj((Object)2);
  70.         popmatrix();
  71.         swapbuffers();
  72.  
  73.         if (qtest()) {
  74.             but = qread(&val);
  75.             but = qread(&val);    /* swallow up event */
  76.  
  77.             switch (but) {
  78.  
  79.             case SKEY:
  80.                 scale(scal, scal, scal);
  81.                 break;
  82.             case XKEY:
  83.                 translate(tdir, 0.0, 0.0);
  84.                 break;
  85.             case YKEY:
  86.                 translate(0.0, tdir, 0.0);
  87.                 break;
  88.             case ZKEY:
  89.                 translate(0.0, 0.0, tdir);
  90.                 break;
  91.             case MINUSKEY:
  92.                 tdir = -tdir;
  93.  
  94.                 if (scal < 1.0)
  95.                     scal = 1.0 + SCAL;
  96.                 else
  97.                     scal = 1.0 - SCAL;
  98.  
  99.                 break;
  100.             case EQUALKEY:
  101.                 tdir = TRANS;
  102.                 break;
  103.             case ESCKEY:
  104.             case QKEY:
  105.                 gexit();
  106.                 exit(0);
  107.             default:
  108.                 ;
  109.             }
  110.         }
  111.     }
  112. }
  113.  
  114. makecubes(fill)
  115.     int    fill;
  116. {
  117.     makeobj((Object)(fill + 2));
  118.         if (!fill)
  119.             color(BLACK);
  120.  
  121.         pushmatrix();
  122.             translate(0.0, 0.0, CUBE_SIZE);
  123.             if (fill) {
  124.                 color(RED);
  125.                 rectf(-CUBE_SIZE, -CUBE_SIZE, CUBE_SIZE, CUBE_SIZE);
  126.             } else
  127.                 rect(-CUBE_SIZE, -CUBE_SIZE, CUBE_SIZE, CUBE_SIZE);
  128.         popmatrix();
  129.  
  130.         pushmatrix();
  131.             translate(CUBE_SIZE, 0.0, 0.0);
  132.             rotate(900, 'y');
  133.             if (fill) {
  134.                 color(GREEN);
  135.                 rectf(-CUBE_SIZE, -CUBE_SIZE, CUBE_SIZE, CUBE_SIZE);
  136.             } else
  137.                 rect(-CUBE_SIZE, -CUBE_SIZE, CUBE_SIZE, CUBE_SIZE);
  138.         popmatrix();
  139.  
  140.         pushmatrix();
  141.             translate(0.0, 0.0, -CUBE_SIZE);
  142.             rotate(1800, 'y');
  143.             if (fill) {
  144.                 color(BLUE);
  145.                 rectf(-CUBE_SIZE, -CUBE_SIZE, CUBE_SIZE, CUBE_SIZE);
  146.             } else 
  147.                 rect(-CUBE_SIZE, -CUBE_SIZE, CUBE_SIZE, CUBE_SIZE);
  148.         popmatrix();
  149.  
  150.         pushmatrix();
  151.             translate(-CUBE_SIZE, 0.0, 0.0);
  152.             rotate(-900, 'y');
  153.             if (fill) {
  154.                 color(CYAN);
  155.                 rectf(-CUBE_SIZE, -CUBE_SIZE, CUBE_SIZE, CUBE_SIZE);
  156.             } else
  157.                 rect(-CUBE_SIZE, -CUBE_SIZE, CUBE_SIZE, CUBE_SIZE);
  158.         popmatrix();
  159.  
  160.         pushmatrix();
  161.             translate(0.0, CUBE_SIZE, 0.0);
  162.             rotate(-900, 'x');
  163.             if (fill) {
  164.                 color(MAGENTA);
  165.                 rectf(-CUBE_SIZE, -CUBE_SIZE, CUBE_SIZE, CUBE_SIZE);
  166.             } else
  167.                 rect(-CUBE_SIZE, -CUBE_SIZE, CUBE_SIZE, CUBE_SIZE);
  168.         popmatrix();
  169.  
  170.         pushmatrix();
  171.             translate(0.0, -CUBE_SIZE, 0.0);
  172.             rotate(900, 'x');
  173.             if (fill) {
  174.                 color(YELLOW);
  175.                 rectf(-CUBE_SIZE, -CUBE_SIZE, CUBE_SIZE, CUBE_SIZE);
  176.             } else
  177.                 rect(-CUBE_SIZE, -CUBE_SIZE, CUBE_SIZE, CUBE_SIZE);
  178.         popmatrix();
  179.  
  180.     closeobj();
  181. }
  182.